package com.sell.demo.util;

import com.fasterxml.jackson.annotation.JsonIgnore;

public class Result<T> {
    private int errorno = 0;
    private String message = "";
    private T data = null;
    private long timestamp = 0;

    public Result() {
        this(0, "", null);
    }

    public Result(int errorno, String message, T data) {
        this.errorno = errorno;
        this.message = message;
        this.data = data;
        this.timestamp = System.currentTimeMillis() / 1000;
    }

    

    public int getErrorno() {
		return errorno;
	}

	public void setErrorno(int errorno) {
		this.errorno = errorno;
	}

	public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    @JsonIgnore
    public boolean isSuccess() {
        return this.errorno == 0;
    }

    @JsonIgnore
    public boolean isError() {
        return this.errorno != 0;
    }

    /**
     * 成功
     * @param data
     * @return
     */
    public static Result success(Object data) {
        return new Result(0, "", data);
    }

    /**
     * 失败
     * @param errorno
     * @param message
     * @return
     */
    public static Result error(int errorno, String message) {
        return new Result(errorno, message, null);
    }
}
